/**
 * Created by ZY on 2018/01/06
 */
let _ = require('lodash'),
  util = require('../helper/util'),
  errCode = require('../../conf/errorCode'),
  logger = require('../helper/logger'),
  service = require('../services/vehicleService');

var tagLogger = new logger.TagLogger('VEHICLE_CONTROLLER');

exports.getVehicleBrandByCapital = function(req, res, next) {
  let {capital} = req.query;
  service.getVehicleBrandByCapital(
    capital,
    util.getHandle(req, res, errCode.GET_VEHICLE_LIST_BY_CAPITAL),
  );
};

exports.getVehicleSpecByModelId = function(req, res, next) {
  let {modelId} = req.query;
  service.getVehicleSpecByModelId(
    modelId,
    util.getHandle(req, res, errCode.GET_VEHICLE_LIST_BY_CAPITAL),
  );
};

exports.getVehicleSpecBySpecId = function(req, res, next) {
  let {specId} = req.params;
  service.getVehicleSpecBySpecId(
    specId,
    util.getHandle(req, res, errCode.GET_VEHICLE_SPEC_BY_SPECID),
  );
};

exports.updateSpecData = function(req, res, next) {
  let {specId} = req.params;
  service.updateSpecData(
    specId,
    req.body,
    util.getHandle(req, res, errCode.UPDATE_VEHICLE_SPEC_BY_SPECID),
  );
};

exports.getCarType = function(req, res, next) {
  service.getCarType(util.getHandle(req, res, errCode.GET_CAR_TYPE));
};

exports.getModelDetailBySpecId = function(req, res, next) {
  let {modelId} = req.query;
  service.getModelDetailBySpecId(
    modelId,
    util.getHandle(req, res, errCode.GET_MODEL_DETAIL_BY_SPECID),
  );
};

exports.updateModelDetailByModelId = function(req, res, next) {
  let {modelId} = req.params;
  service.updateModelDetailByModelId(
    modelId,
    req.body,
    util.getHandle(req, res, errCode.UPDATE_VEHICLE_MODEL_BY_MODELID),
  );
};

exports.getBrandListByNamePrefix = function(req, res, next) {
  let {namePrefix} = req.query;
  service.getBrandListByNamePrefix(
    namePrefix,
    util.getHandle(req, res, errCode.GET_BRAND_LIST_BY_NAME_PREFIX),
  );
};

exports.addModel = function(req, res, next) {
  service.addModel(req.body, util.getHandle(req, res, errCode.ADD_MODEL));
};
